package com.financial.business.base.service;

import com.financial.business.base.connector.BalanceBusinessFeign;
import com.financial.business.base.connector.HeemoneyBusinessFeign;
import com.financial.business.base.connector.IntegralBusinessFeign;
import com.financial.business.base.connector.YsBusinessFeign;
import com.financial.business.base.utils.apiresult.ApiResult;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Davidbieber
 * @description 基础策略静态类
 * @email davidbieber@163.com
 * @date 2019/12/12 4:00 PM
 */
public enum FinancialBaseConstants {

    /*报备*/
    YS_REPORT("101") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.ysReport(requestParam);
        }
    },
    HEEMONEY_REPORT("201") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.report(requestParam);
        }
    },
    /*支付*/
    YS_PAY("102") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.ysPay(requestParam);
        }
    },
    HEEMONEY_PAY("202") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.pay(requestParam);
        }
    },
    BALANCE_PAY("302") {
        @Autowired
        private BalanceBusinessFeign balanceBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return balanceBusinessFeign.pay(requestParam);
        }
    },
    INTEGRAL_PAY("402") {
        @Autowired
        private IntegralBusinessFeign integralBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return integralBusinessFeign.pay(requestParam);
        }
    },
    /*分账*/
    YS_SPLIT("103") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.ysSplit(requestParam);
        }
    },
    HEEMONEY_SPLIT("203") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.split(requestParam);
        }
    },
    /*退款*/
    YS_REFUND("303") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.refund(requestParam);
        }
    },
    HEEMONEY_REFUND("403") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.refund(requestParam);
        }
    },
    BALANCE_REFUND("104") {
        @Autowired
        private BalanceBusinessFeign balanceBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return balanceBusinessFeign.refund(requestParam);
        }
    },
    INTEGRAL_REFUND("204") {
        @Autowired
        private IntegralBusinessFeign integralBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return integralBusinessFeign.refund(requestParam);
        }
    },
    /*提现*/
    YS_WITHDRAWAL("304") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.withdrawal(requestParam);
        }
    },
    HEEMONEY_WITHDRAWAL("404") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.withdrawal(requestParam);
        }
    },
    /*代付*/
    YS_PAYMENT("106") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.payment(requestParam);
        }
    },
    HEEMONEY_PAYMENT("206") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.payment(requestParam);
        }
    },
    BALANCE_PAYMENT("306") {
        @Autowired
        private BalanceBusinessFeign balanceBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return balanceBusinessFeign.payment(requestParam);
        }
    },
    INTEGRAL_PAYMENT("406") {
        @Autowired
        private IntegralBusinessFeign integralBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return integralBusinessFeign.payment(requestParam);
        }
    },
    /*查询*/
    YS_QUERY("107") {
        @Autowired
        private YsBusinessFeign ysBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return ysBusinessFeign.query(requestParam);
        }
    },
    HEEMONEY_QUERY("207") {
        @Autowired
        private HeemoneyBusinessFeign heemoneyBusinessFeign;

        @Override
        ApiResult routerConverter(String requestParam) {
            return heemoneyBusinessFeign.query(requestParam);
        }
    };

    abstract ApiResult routerConverter(String requestParam);

    private String business_type;

    FinancialBaseConstants(String business_type) {
        this.business_type = business_type;
    }

    public String getBusiness_type() {
        return business_type;
    }

    public void setBusiness_type(String business_type) {
        this.business_type = business_type;
    }

    public static ApiResult valueOf(String business_type, String requestParam) {
        ApiResult apiResult = null;
        for (FinancialBaseConstants financialBaseConstants : FinancialBaseConstants.values()) {
            if (financialBaseConstants.getBusiness_type().equals(business_type)) {
                apiResult = financialBaseConstants.routerConverter(requestParam);
                return apiResult;
            }
        }
        return apiResult;
    }

    public static List EnumToList() {
        List list = Lists.newArrayList();
        for (FinancialBaseConstants financialBaseConstants : FinancialBaseConstants.values()) {
            list.add(financialBaseConstants.getBusiness_type());
        }
        return list;
    }
}
